package kr.co.m2soft.model.page.elements
{
	import kr.co.m2soft.model.CommonModel;
	import kr.co.m2soft.model.IBaseModelParser;
	import kr.co.m2soft.model.elements.Font;
	import kr.co.m2soft.model.elements.TA;
	
	import mx.collections.ArrayCollection;

	public class TX extends PGElement implements IBaseModelParser
	{
		private var commonModel:CommonModel = CommonModel.getInstance();
		private var _le:Number;
		private var _to:Number;
		private var _ri:Number;
		private var _bo:Number;
		private var _tid:int;
		private var _fn:String;
		private var _pt:int;
		private var _cl:String;
		private var _cb:int = 0;
		private var _ci:int = 0;
		private var _cu:int = 0;
		private var _cs:int = 0;
		private var _cr:int = 0;
		private var _sc:int;
		private var _ls:int = 0;
		private var _ha:int = 0;
		private var _ft:int = 0;
		private var _ta:TA;
		private var _font:Font;
		private var _fontList:ArrayCollection;
		private var _TAList:ArrayCollection;
		private var _text:String = "";
		
		public function TX()
		{
		}
		
		override public function parser():void
		{
			
			super.parser();
			
			_fontList = commonModel.mml.head.fontList;
			_TAList = commonModel.mml.head.TAList;
			_tid = dataProvider.hasOwnProperty("@tid") ? dataProvider.@tid : _tid;
			if(_tid != 0){
				try{
					_ta = getTA(_tid);
					_font = getFont(ta.fi);
				}catch(e:RangeError){}
				_fn = _font.name;
				_pt = ta.pt;
				_cl = ta.cl;
				_cb = ta.cb;
				_ci = ta.ci;
				_cu = ta.cu;
				_cs = ta.cs;
				_cr = ta.cr;
				_sc = ta.sc;
				_ls = ta.ls;
			}
			_le = dataProvider.hasOwnProperty("@le") ? dataProvider.@le : _le;
			_to = dataProvider.hasOwnProperty("@to") ? dataProvider.@to : _to;
			_ri = dataProvider.hasOwnProperty("@ri") ? dataProvider.@ri : _ri;
			_bo = dataProvider.hasOwnProperty("@bo") ? dataProvider.@bo : _bo;
			_fn = dataProvider.hasOwnProperty("@fn") ? dataProvider.@st : _fn;
			_pt = dataProvider.hasOwnProperty("@pt") ? dataProvider.@pt : _pt;
			_cl = dataProvider.hasOwnProperty("@cl") ? dataProvider.@cl : _cl;
			_cb = dataProvider.hasOwnProperty("@cb") ? dataProvider.@cb : _cb;
			_ci = dataProvider.hasOwnProperty("@ci") ? dataProvider.@ci : _ci;
			_cu = dataProvider.hasOwnProperty("@cu") ? dataProvider.@cu : _cu;
			_cs = dataProvider.hasOwnProperty("@cs") ? dataProvider.@cs : _cs;
			_cr = dataProvider.hasOwnProperty("@cr") ? dataProvider.@cr : _cr;
			_sc = dataProvider.hasOwnProperty("@sc") ? dataProvider.@sc : _sc;
			_ls = dataProvider.hasOwnProperty("@ls") ? dataProvider.@ls : _ls;
			_ha = dataProvider.hasOwnProperty("@ha") ? dataProvider.@ha : _ha;
			_ft = dataProvider.hasOwnProperty("@ft") ? dataProvider.@ft : _ft;
			_text = String(dataProvider);
			
		}
		private function getTA(index:int):TA
		{
			for each(var item:TA in commonModel.mml.head.TAList){
				if(index == item.eid){
					break;
				}
			}
			return item;
		}
		private function getFont(index:int):Font
		{
			for each(var item:Font in commonModel.mml.head.fontList){
				if(index == item.eid){
					break;
				}
			}
			return item;
		}
		public function get le():Number
		{
			return _le;
		}

		public function set le(value:Number):void
		{
			_le = value;
		}

		public function get to():Number
		{
			return _to;
		}

		public function set to(value:Number):void
		{
			_to = value;
		}

		public function get ri():Number
		{
			return _ri;
		}

		public function set ri(value:Number):void
		{
			_ri = value;
		}

		public function get bo():Number
		{
			return _bo;
		}

		public function set bo(value:Number):void
		{
			_bo = value;
		}

		public function get tid():int
		{
			return _tid;
		}

		public function set tid(value:int):void
		{
			_tid = value;
		}

		public function get fn():String
		{
			return _fn;
		}

		public function set fn(value:String):void
		{
			_fn = value;
		}

		public function get pt():int
		{
			return _pt;
		}

		public function set pt(value:int):void
		{
			_pt = value;
		}

		public function get cl():String
		{
			return _cl;
		}

		public function set cl(value:String):void
		{
			_cl = value;
		}

		public function get cb():int
		{
			return _cb;
		}

		public function set cb(value:int):void
		{
			_cb = value;
		}

		public function get ci():int
		{
			return _ci;
		}

		public function set ci(value:int):void
		{
			_ci = value;
		}

		public function get cu():int
		{
			return _cu;
		}

		public function set cu(value:int):void
		{
			_cu = value;
		}

		public function get cs():int
		{
			return _cs;
		}

		public function set cs(value:int):void
		{
			_cs = value;
		}

		public function get cr():int
		{
			return _cr;
		}

		public function set cr(value:int):void
		{
			_cr = value;
		}

		public function get sc():int
		{
			return _sc;
		}

		public function set sc(value:int):void
		{
			_sc = value;
		}

		public function get ls():int
		{
			return _ls;
		}

		public function set ls(value:int):void
		{
			_ls = value;
		}
		/*
		[Inspectable(enumeration="0,1", defaultValue="0" )]
		public function get ha():int
		{
			return _ha;
		}

		public function set ha(value:int):void
		{
			_ha = value;
		}
		*/

		public function get ft():int
		{
			return _ft;
		}
		[Inspectable(enumeration="0,1", defaultValue="0" )]
		public function set ft(value:int):void
		{
			_ft = value;
		}

		public function get ta():TA
		{
			return _ta;
		}
		
		public function set ta(value:TA):void
		{
			_ta = value;
		}
		
		public function get text():String
		{
			return _text;
		}
		
		public function set text(value:String):void
		{
			_text = value;
		}
	}
}